package org.putrpctorest.expression;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ParameterGroup extends AbstractExpression {
	
	public ParameterGroup(String id) {
		super(id);
	}
	
	public ParameterGroup(ParameterGroup parameterGroup) {
		super(parameterGroup.getId());
		this.parameterList = new ArrayList<String>(parameterGroup.getParameterList());
	}

	private List<String> parameterList = new ArrayList<String>();
	
	public void setParameterList(List<String> parameterList) {
		this.parameterList = new ArrayList<String>(parameterList); 
	}
	
	public List<String> getParameterList() {
		return Collections.unmodifiableList(parameterList);
	}
	
	@Override
	public ExpressionResult route(Map<String, Object> params) throws Exception {
		if (verifyInformedParameters(params)) {
			return getChildren().get(0).route(params);	
		}
		else {
			return new ExpressionResult();
		}
	}

	
	private boolean verifyInformedParameters(Map<String, Object> params) {
		for(String paramName:parameterList) {
			if (params.get(paramName) != null) {
				return true;
			}
		}
		return false;
	}

	@Override
	public String getType() {
		return "parameter-group";
	}

}
